import java.util.Random;

/**
 * Created by brss on 2018/9/11.
 */
public class Main {

    // 测试使用Stack运行opCount个push和pop操作所使用的时间，单位：秒
    private static double testQueue(Stack<Integer> stack, int opCount) {
        long startTime = System.nanoTime();
        Random random = new Random();
        for (int i = 0 ; i < opCount ; i++) {
            stack.push(random.nextInt(Integer.MAX_VALUE));
        }
        for (int i = 0 ; i < opCount ;i++) {
            stack.pop();
        }
        long endTime = System.nanoTime();
        return (endTime - startTime) / 1000000000.0;
    }

    public static void main(String[] args) {
        int opCount = 100000;
        ArrayStack<Integer> arrayStack = new ArrayStack<>();
        double time1 = testQueue(arrayStack, opCount);
        System.out.println("ArrayStack,time:"+time1+" s");

        LinkedListStack<Integer> linkedListStack = new LinkedListStack<>();
        double time2 = testQueue(linkedListStack, opCount);
        System.out.println("LinkedListStack,time:"+time2+" s");
    }
}
